package cn.mrlong.recordandplay;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

public class Main2Activity extends Activity {

    private SeekBar mSeekBar;
    private String path = "http://file.kuyinyun.com/group1/M00/90/B7/rBBGdFPXJNeAM-nhABeMElAM6bY151.mp3";
    //private String path = "http://172.16.212.137:8080/mp3/2.mp3";
    private PlayerUtil mPlayer;
    private EditText mEditText;
    private TextView statusText;
    private Button play;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        mSeekBar = (SeekBar) findViewById(R.id.seekBar);
        mEditText = (EditText) findViewById(R.id.editText);
        statusText = (TextView) findViewById(R.id.status);
        mEditText.setText(path);
        play = findViewById(R.id.play);
        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPlayer = new PlayerUtil();
                mPlayer.playUrl(mEditText.getText().toString().trim(), new PlayerUtil.MediaPlayerStatuListener() {
                    @Override
                    public void currentStatu(String status) {
                        statusText.setText(status);
                    }

                    @Override
                    public void progress(double i) {
                        Log.e("===>", "" + i);
                        int p = (int) (i * 100);
                        mSeekBar.setProgress(p);
                    }

                    @Override
                    public void progress2(long i) {
                        mSeekBar.setSecondaryProgress((int) i);
                    }
                });
            }
        });
    }
}
